package personal.dao.accounting;

import java.util.List;

import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;

import org.springframework.stereotype.Repository;

import personal.domain.accounting.ExternalEntity;


@Repository
public class ExternalEntityDAOImpl implements ExternalEntityDAO {
	
	@PersistenceContext(unitName="accountingPU")
	private EntityManager em;

	@SuppressWarnings("unchecked")
	@Override
	public List<ExternalEntity> getAllExternalEntities() {
		return em.createNamedQuery(ExternalEntity.GET_ALL_ENTITIES).getResultList();
	}

	@Override
	public ExternalEntity saveExternalEntity(ExternalEntity entity) {
		return em.merge(entity);
	}

	@Override
	public ExternalEntity getEntity(Long entityId) {
		ExternalEntity entity = new ExternalEntity();
		entity.setEntityId(entityId);
		return em.find(ExternalEntity.class, entity);
	}
}
